1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package com.google.common.collect;
17
18 import static com.google.common.base.Preconditions.checkNotNull;
19
20 import com.google.common.annotations.GwtCompatible;
21
22 import java.util.Comparator;
23
24 import javax.annotation.Nullable;
25
26
27
28
29
30
31 @GwtCompatible(emulated = true)
32 @SuppressWarnings("serial")
33 final class EmptyImmutableSortedMap<K, V> extends ImmutableSortedMap<K, V> {
34 private final transient ImmutableSortedSet<K> keySet;
35
36 EmptyImmutableSortedMap(Comparator<? super K> comparator) {
37 this.keySet = ImmutableSortedSet.emptySet(comparator);
38 }
39
40 EmptyImmutableSortedMap(
41 Comparator<? super K> comparator, ImmutableSortedMap<K, V> descendingMap) {
42 super(descendingMap);
43 this.keySet = ImmutableSortedSet.emptySet(comparator);
44 }
45
46 @Override
47 public V get(@Nullable Object key) {
48 return null;
49 }
50
51 @Override
52 public ImmutableSortedSet<K> keySet() {
53 return keySet;
54 }
55
56 @Override
57 public int size() {
58 return 0;
59 }
60
61 @Override
62 public boolean isEmpty() {
63 return true;
64 }
65
66 @Override
67 public ImmutableCollection<V> values() {
68 return ImmutableList.of();
69 }
70
71 @Override
72 public String toString() {
73 return "{}";
74 }
75
76 @Override
77 boolean isPartialView() {
78 return false;
79 }
80
81 @Override
82 public ImmutableSet<Entry<K, V>> entrySet() {
83 return ImmutableSet.of();
84 }
85
86 @Override
87 ImmutableSet<Entry<K, V>> createEntrySet() {
88 throw new AssertionError("should never be called");
89 }
90
91 @Override
92 public ImmutableSetMultimap<K, V> asMultimap() {
93 return ImmutableSetMultimap.of();
94 }
95
96 @Override
97 public ImmutableSortedMap<K, V> headMap(K toKey, boolean inclusive) {
98 checkNotNull(toKey);
99 return this;
100 }
101
102 @Override
103 public ImmutableSortedMap<K, V> tailMap(K fromKey, boolean inclusive) {
104 checkNotNull(fromKey);
105 return this;
106 }
107
108 @Override
109 ImmutableSortedMap<K, V> createDescendingMap() {
110 return new EmptyImmutableSortedMap<K, V>(Ordering.from(comparator()).reverse(), this);
111 }
112 }